package com.deng.common.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.deng.common.SQLHelper;
import com.deng.common.dao.IIndicate;
import com.deng.common.vo.IndicateVo;

public class IndicateImpl extends SQLHelper implements IIndicate {

	public List<IndicateVo> getAllIndicate() {
		try{
			Connection conn = getConnect();
			ResultSet rs = queryData(conn,"select * from KPI_INDICATE order by name");
			List<IndicateVo> list = new ArrayList<IndicateVo>();
			while(rs.next()){
				IndicateVo vo = new IndicateVo();
				vo.id = rs.getInt("id");
				vo.name = rs.getString("name");
				vo.description = rs.getString("description");
				vo.unit = rs.getString("unit");
				vo.formula = rs.getString("formula");
				vo.function_name = rs.getString("function_name");
				list.add(vo);
			}
			freeConnection(conn);
			return list;
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	
	}

	public IndicateVo getIndicateById(int id) {
		try{
			Connection conn = getConnect();
			ResultSet rs = queryData(conn,"select * from KPI_INDICATE where id = "+id);
			if(rs.next()){
				IndicateVo vo = new IndicateVo();
				vo.id = rs.getInt("id");
				vo.name = rs.getString("name");
				vo.description = rs.getString("description");
				vo.unit = rs.getString("unit");
				vo.formula = rs.getString("formula");
				vo.function_name = rs.getString("function_name");
				freeConnection(conn);
				return vo;
			}
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}

	public Integer updateIndicate(IndicateVo vo) {
//		try{
//			int i = updateData("update t_sys_stat_department " +
//					"	set function_name = '"+vo.function_name+"'" +
//					"	where id = "+vo.id);
//			if(i == 1){
//				return getOrganizationById(vo.id);
//			}else{
//				return null;
//			}			
//		}catch(Exception ex){
//			ex.printStackTrace();
//		}
		return 0;
	}

}
